*** REPLICATION FILE FOR "TERRORISM AND CHILD MORTALITY" (https://doi.org/10.1002/hec.4757) ***
*** Daniel Meierrieks and Max Schaub ***

* Install Ados
* (PLEASE INSTALL AS NECESSARY) 
/*
ssc install ihstrans, replace
ssc install reghdfe, replace
ssc install outreg2, replace
ssc install weakiv, replace
ssc install xtivreg2, replace
ssc install plausexog, replace
ssc install xtevent, replace
ssc install ftools, replace
net install st0455.pkg, replace
*/

* Folders
* (PLEASE CHANGE ACCORDINGLY)
global folder ""
cd "${folder}"

use "terrorism_childmort_data.dta", clear

* Create Main Terror Variable and Other Controls
* (Inverse hyperbolic sine transformation is very similar to log-transformation, but defined for zero-observation cases; variables are transformed to account for skewness)
sort gid year
drop if year>2017
g t1=terror_incident_pp+terror_nvictims_pp
ihstrans t1
rename ihs_ terror
drop t1
ihstrans terror_incident_pp
rename ihs_ terror1
ihstrans terror_nvictims_pp
rename ihs_t terror2
ihstrans night
rename ihs_n night 
ihstrans scad_protest_events
rename ihs_scad protest 
ihstrans statereach
rename ihs_st infra
ihstrans urban_ih_interpolate
rename ihs_urban urban
ihstrans edufem
rename ihs_ed femedu

* Summary Statistics
quietly: reghdfe mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
g insample=e(sample)
preserve
keep if insample==1
outreg2 using "${folder}s1_summary.xls", sum(log) replace
restore

* Baseline OLS
** Parsimonious (Full Sample)
reghdfe mortU5 terror , absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", replace stat(coef se) nocons bdec(3) sdec(3)
** Parsimonious (Reduced Sample)
reghdfe mortU5 terror if insample==1, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** With Baseline Controls for Nightlights, Urbanization, Infrastructure and Climate
reghdfe mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Alternative DV: mortNeo + mortU1
reghdfe mortNeo terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
reghdfe mortU1 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Alternative Terrorism: Incidents p.c. + Casualties p.c.
reghdfe mortU5 terror1 night infra urban femedu temp spei if insample==1, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
reghdfe mortU5 terror2 night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Allow for Influence of Additional Lags of Terror Variable
reghdfe mortU5 l(0/2).terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}1table_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
nlcom (_b[terror]+_b[l1.terror] +_b[l2.terror])

* Robustness: Measurement of Terrorism
** Terrorism Index (Not Weighted by Population)
g aux1=terror_incident+ terror_nvictims
ihstrans aux1
reghdfe mortU5 ihs_aux1 night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2atable_fe.xls", replace stat(coef se) nocons bdec(3) sdec(3)
drop aux1 ihs_aux*
** Alternative Terrorism Index (Weighs Casualties More Strongly)
g aux1=terror_incident_pp + (4* terror_nvictims_pp )
ihstrans aux1
reghdfe mortU5 ihs_aux1 night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2atable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
drop aux1 ihs_aux*
** Alternative Terrorism Index (Weighs Casualties More Strongly)
g aux1=terror_incident_pp + (8* terror_nvictims_pp )
ihstrans aux1
reghdfe mortU5 ihs_aux1 night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2atable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
drop aux1 ihs_aux*
** Geometric Mean of Both Terrorism Measures
g aux1=terror_incident_pp*terror_nvictims_pp
gen aux2 = sqrt(aux1)
ihstrans aux2
reghdfe mortU5 ihs_aux2 night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2atable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
drop aux1 aux2 ihs_aux*
** Binary Terrorism Measure
reghdfe mortU5 terror_incident_binary night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2atable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)

* Robustness: Additional Controls
** Driscoll-Kraay Standard Errors
xtscc mortU5 terror night infra urban femedu temp spei i.year, fe
outreg2 using "${folder}s2btable_fe.xls", replace stat(coef se) nocons bdec(3) sdec(3)
** Two-Way Clustered SE
reghdfe mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid year)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Also Control for Population Size
ihstrans pop
reghdfe mortU5 terror night infra urban femedu temp spei ihs_pop, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Replace Nightlights with Gross Cell Product
ihstrans gcp_ppp_interpolate
reghdfe mortU5 terror ihs_gcp_ppp_interpolate infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Replace Travel Time Variable
ihstrans marketaccess
reghdfe mortU5 terror night ihs_marketaccess urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Also Control for Excluded Groups
reghdfe mortU5 terror night infra urban femedu temp spei excluded, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Use IHS Transformations of spei temp
ihstrans spei temp
reghdfe mortU5 terror night infra urban femedu ihs_temp ihs_spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Use IHS Transformation of DV
ihstrans mortU5
reghdfe ihs_mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
drop ihs_gcp_ppp ihs_pop ihs_marketaccess ihs_temp ihs_spei ihs_mortU5
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Use Lags of All Explanatory Variables
reghdfe f.mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Use 4-Year Periods Instead of Annual Data (Role of Interpolation Effects)
preserve
g period=1
replace period=2 if year>2003
replace period=3 if year>2007
replace period=4 if year>2011
replace period=. if year>2015
collapse (mean) mortU5 terror night infra urban femedu temp spei, by(period gid)
reghdfe mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.period) vce(cluster gid)
outreg2 using "${folder}s2btable_fe.xls", append stat(coef se) nocons bdec(3) sdec(3)
restore
drop insample

* IV-Estimation
** Create Variables
tab year, g(time)
** DV: Terror
** Estimation
xtivreg2 mortU5 (terror=protest) night infra urban femedu temp spei time*, fe cluster(gid) endog(terror) first
g insample2=e(sample)
outreg2 using "${folder}2table_iv.xls", replace stat(coef se) nocons bdec(3) sdec(3)
weakiv, level(90)
xtivreg2 mortU5 (terror=l.protest) night infra urban femedu temp spei time*, fe cluster(gid) endog(terror) first
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
weakiv, level(90)
** Reduced Form
bysort gid: egen aux1=mean(terror)
g aux2=0
replace aux2=1 if aux1>0 & aux1!=0
*** Full Sample
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1, absorb(i.gid i.year) vce(cluster gid) 
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
*** No Terror
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1 & aux2==0 , absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
*** Terror
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1 & aux2==1, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Plausibly Exogenous Framework
*** Prepare Data
*** (Centering by gid and year "creates" fixed-effects via transformation; otherwise plausexog would not work properly)
bysort gid: center mortU5 terror protest night infra urban femedu temp spei if insample2==1
bysort year: center c_mortU5 c_terror c_protest c_night c_infra c_urban c_femedu c_temp c_spei if insample2==1
*** Plausibly Exogenous Framework
plausexog uci c_c_mortU5  c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei (c_c_terror=c_c_protest), cluster(id) gmin(-0.054) gmax(0)
** PVAR Granger (Terror-Protest)
pvar c_c_terror c_c_protest, vce(cluster gid)
pvargranger
pvar c_c_terror c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei)
pvargranger
pvar c_c_terror c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei) lag(2)
pvargranger
pvar c_c_terror c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei) gmmstyle instlags(2/4) overid lag(2)
pvargranger
drop c_* aux*
drop insample*
** DV: Terror1
** Estimation
xtivreg2 mortU5 (terror1=protest) night infra urban femedu temp spei time*, fe cluster(gid) endog(terror1) first
g insample2=e(sample)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
weakiv, level(90)
xtivreg2 mortU5 (terror1=l.protest) night infra urban femedu temp spei time*, fe cluster(gid) endog(terror1) first
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
weakiv, level(90)
** Reduced Form
bysort gid: egen aux1=mean(terror1)
g aux2=0
replace aux2=1 if aux1>0 & aux1!=0
*** Full Sample
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1, absorb(i.gid i.year) vce(cluster gid) 
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
*** No Terror
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1 & aux2==0 , absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
*** Terror
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1 & aux2==1, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Plausibly Exogenous Framework
*** Prepare Data
*** (Centering by gid and year "creates" fixed-effects via transformation; otherwise plausexog would not work properly)
bysort gid: center mortU5 terror1 protest night infra urban femedu temp spei if insample2==1
bysort year: center c_mortU5 c_terror1 c_protest c_night c_infra c_urban c_femedu c_temp c_spei if insample2==1
*** Plausibly Exogenous Framework
plausexog uci c_c_mortU5  c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei (c_c_terror1=c_c_protest), cluster(id) gmin(-0.054) gmax(0)
** PVAR Granger (Terror-Protest)
pvar c_c_terror1 c_c_protest, vce(cluster gid)
pvargranger
pvar c_c_terror1 c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei)
pvargranger
pvar c_c_terror1 c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei) lag(2)
pvargranger
pvar c_c_terror1 c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei) gmmstyle instlags(2/4) overid lag(2)
pvargranger
* Create Graph for Appendix (Study Violation of Exclusion Restriction)
*plausexog uci c_c_mortU5  c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei (c_c_terror=c_c_protest), vce(cluster gid) gmin(-0.05) gmax(0.12) graph(c_c_terror) level(0.9)
drop c_* aux*
drop insample*
** DV: Terror2
** Estimation
xtivreg2 mortU5 (terror2=protest) night infra urban femedu temp spei time*, fe cluster(gid) endog(terror2) first
g insample2=e(sample)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
weakiv, level(90)
xtivreg2 mortU5 (terror2=l.protest) night infra urban femedu temp spei time*, fe cluster(gid) endog(terror2) first
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
weakiv, level(90)
** Reduced Form
bysort gid: egen aux1=mean(terror2)
g aux2=0
replace aux2=1 if aux1>0 & aux1!=0
*** Full Sample
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1, absorb(i.gid i.year) vce(cluster gid) 
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
*** No Terror
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1 & aux2==0 , absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
*** Terror
reghdfe mortU5 protest night infra urban femedu temp spei if insample2==1 & aux2==1, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}2table_iv.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Plausibly Exogenous Framework
*** Prepare Data
*** (Centering by gid and year "creates" fixed-effects via transformation; otherwise plausexog would not work properly)
bysort gid: center mortU5 terror2 protest night infra urban femedu temp spei if insample2==1
bysort year: center c_mortU5 c_terror2 c_protest c_night c_infra c_urban c_femedu c_temp c_spei if insample2==1
*** Plausibly Exogenous Framework
plausexog uci c_c_mortU5  c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei (c_c_terror2=c_c_protest), cluster(id) gmin(-0.0615) gmax(0)
** PVAR Granger (Terror-Protest)
pvar c_c_terror2 c_c_protest, vce(cluster gid)
pvargranger
pvar c_c_terror2 c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei)
pvargranger
pvar c_c_terror2 c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei) lag(2)
pvargranger
pvar c_c_terror2 c_c_protest, vce(cluster gid) exog(c_c_night c_c_infra c_c_urban c_c_femedu c_c_temp c_c_spei) gmmstyle instlags(2/4) overid lag(2)
pvargranger
drop c_* aux*
drop insample*

* Panel Event-Study
** Main Treatment Variable: Terrorism above Mean + At Least Two Years with Incidents
bysort gid: egen t1=mean(terror)
g t2=0
replace t2=1 if t1>=0.053
bysort gid: egen t3=sum( terror_incident_binary )
g t4=0
replace t4=1 if t3>=2
g t5=0
replace t5=1 if terror!=0 & t2==1 & t4==1 
bysort gid: egen firsttime = min(cond(t5 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s5_event.xls", replace stat(coef se) nocons bdec(3) sdec(3)
xteventplot,  nopostpval noprepval  levels(95) nosupt
xteventtest, allpre cumul
graph save graph_terror_m1, replace
drop t1 t2 t3 t4 t5 first*
** Main Treatment Variable: Terrorism Incidents, Terrorism above Mean + At Least Two Years with Incidents
bysort gid: egen t1=mean(terror_incident_pp)
g t2=0
replace t2=1 if t1>=0.82
bysort gid: egen t3=sum( terror_incident_binary )
g t4=0
replace t4=1 if t3>=2
g t5=0
replace t5=1 if terror!=0 & t2==1 & t4==1 
bysort gid: egen firsttime = min(cond(t5 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s5_event.xls", append stat(coef se) nocons bdec(3) sdec(3)
xteventplot,  nopostpval  levels(95) noprepval nosupt  
xteventtest, allpre cumul
graph save graph_terror_m2, replace
drop t1 t2 t3 t4 t5 first*
** Main Treatment Variable: Terrorism Victims, Terrorism above Mean + At Least Two Years with Incidents
bysort gid: egen t1=mean(terror_nvictims_pp)
g t2=0
replace t2=1 if t1>0.0602
bysort gid: egen t3=sum( terror_nvictims_binary )
g t4=0
replace t4=1 if t3>=2
g t5=0
replace t5=1 if terror!=0 & t2==1 & t4==1 
bysort gid: egen firsttime = min(cond(t5 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s5_event.xls", append stat(coef se) nocons bdec(3) sdec(3)
xteventplot,  nopostpval  levels(95) noprepval  nosupt 
xteventtest, allpre cumul
graph save graph_terror_m3, replace
drop t1 t2 t3 t4 t5 first*

* Panel Event-Study: Robustness
** Robustness Treatment Variable I: Any Terrorism + At Least Two Years with Incidents
bysort gid: egen t1=sum( terror_incident_binary )
g t2=0
replace t2=1 if t1>=2
g t3=0
replace t3=1 if terror!=0 & t2==1 
bysort gid: egen firsttime = min(cond(t3 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s6_event_rob.xls", replace stat(coef se) nocons bdec(3) sdec(3)
xteventtest, allpre cumul
drop t1 t2 t3 first*
** Robustness Treatment Variable II: Terrorism above 1 SD + At Least Two Years with Incidents
bysort gid: egen t1=mean(terror)
g t2=0
replace t2=1 if t1>=0.207
bysort gid: egen t3=sum( terror_incident_binary )
g t4=0
replace t4=1 if t3>=2
g t5=0
replace t5=1 if terror!=0 & t2==1 & t4==1 
bysort gid: egen firsttime = min(cond(t5 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s6_event_rob.xls", append stat(coef se) nocons bdec(3) sdec(3)
xteventtest, allpre cumul
drop t1 t2 t3 t4 t5 first*
** Robustness Treatment Variable III: Any Terrorism + At Least Four Years with Incidents
bysort gid: egen t1=sum( terror_incident_binary )
g t2=0
replace t2=1 if t1>=4
g t3=0
replace t3=1 if terror!=0 & t2==1 
bysort gid: egen firsttime = min(cond(t3 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s6_event_rob.xls", append stat(coef se) nocons bdec(3) sdec(3)
xteventtest, allpre cumul
drop t1 t2 t3 first*
** Robustness Treatment Variable IV: Any Terrorism + At Least Seven Years with Incidents
bysort gid: egen t1=sum( terror_incident_binary )
g t2=0
replace t2=1 if t1>=7
g t3=0
replace t3=1 if terror!=0 & t2==1 
bysort gid: egen firsttime = min(cond(t3 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s6_event_rob.xls", append stat(coef se) nocons bdec(3) sdec(3)
xteventtest, allpre cumul
drop t1 t2 t3 first*
** Robustness Treatment Variable V: Baseline Treatment, Drop Grids With Terrorism Below Treatment Value
preserve
bysort gid: egen t1=mean(terror)
g t2=0
replace t2=1 if t1>=0.136
drop if t1<0.136 & t1!=0
bysort gid: egen t3=sum( terror_incident_binary )
g t4=0
replace t4=1 if t3>=2
drop if t4==0 & t2==1
g t5=0
replace t5=1 if terror!=0 & t2==1 & t4==1 
bysort gid: egen firsttime = min(cond(t5 == 1, year, .))
gen byte first = year>= firsttime
* Estimation
xtevent  mortU5 night infra urban femedu temp spei, pol(first) w(4) cluster(gid)
outreg2 using "${folder}s6_event_rob.xls", append stat(coef se) nocons bdec(3) sdec(3)
xteventtest, allpre cumul
drop t1 t2 t3 t4 t5 first*
restore

* Potential Transmission Channels
* Create Uniform Sample
quietly: reghdfe mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
g insample=e(sample)
preserve
keep if insample==1
** Create Variables
** (IHS transformation of incidence-rates to account for skewness) 
ihstrans pf04inc
ihstrans diainci
** Effect of Terrorism on Malaria, Diarrhea and Vaccinations
reghdfe ihs_pf04inc terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4atable_channels.xls", replace stat(coef se) nocons bdec(3) sdec(3)
reghdfe ihs_dia terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4atable_channels.xls", append stat(coef se) nocons bdec(3) sdec(3)
reghdfe dpt3cov terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4atable_channels.xls", append stat(coef se) nocons bdec(3) sdec(3)
reghdfe uweightp terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4atable_channels.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Correlation between Transmission Channels and Outcome
reghdfe mortU5 ihs_pf04inc night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4btable_channels.xls", replace stat(coef se) nocons bdec(3) sdec(3)
reghdfe mortU5 ihs_dia night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4btable_channels.xls", append stat(coef se) nocons bdec(3) sdec(3)
reghdfe mortU5 dpt3cov night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4btable_channels.xls", append stat(coef se) nocons bdec(3) sdec(3)
reghdfe mortU5 uweightp night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}4btable_channels.xls", append stat(coef se) nocons bdec(3) sdec(3)
restore

* Role of Civil Conflict
* Create Conflict Variable (battle deaths p.c., IHS transformed)
g aux1=(ucdp_deaths_total- ucdp_deaths_civilians)/(pop/100000)
ihstrans aux1
rename ihs_aux1 ihs_battledeaths
drop aux1
** Terror Only, Baseline Controls
reghdfe mortU5 terror night infra urban femedu temp spei, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", replace stat(coef se) nocons bdec(3) sdec(3)
** With Conflict Controls
reghdfe mortU5 terror night infra urban femedu temp spei ihs_battledeaths, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Binary Conflict Measure
g aux1=0
replace aux1=1 if ihs_battledeaths>0
rename aux1 battledeaths_binary
reghdfe mortU5 terror night infra urban femedu temp spei battledeaths_binary, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Use Binary for Victims>25
g aux1=(ucdp_deaths_total- ucdp_deaths_civilians)
g aux2=0
replace aux2=1 if aux1>24
rename aux2 conflict_binary
reghdfe mortU5 terror night infra urban femedu temp spei conflict_binary, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
drop aux*
** Also Include Civilian Deaths (doube-counting)
g aux1=ucdp_deaths_total/(pop/100000)
ihstrans aux1
rename ihs_aux1 ihs_totaldeaths
drop aux1
reghdfe mortU5 terror night infra urban femedu temp spei ihs_totaldeaths, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Drop Observations with Civil Conflict
reghdfe mortU5 terror night infra urban femedu temp spei if battledeaths_binary==0, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
** Drop GIDs with Civil Conflict
bysort gid: egen aux1=mean(battledeaths_binary)
reghdfe mortU5 terror night infra urban femedu temp spei if aux1==0, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
drop aux1
** Conflict Only
reghdfe mortU5 night infra urban femedu temp spei ihs_battledeaths, absorb(i.gid i.year) vce(cluster gid)
outreg2 using "${folder}s0table_conflict.xls", append stat(coef se) nocons bdec(3) sdec(3)
